<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>首页内容版块</title>
<jsp:include page="/common/link.jsp"></jsp:include>
<link rel="stylesheet" type="text/css" media="all" href="/portal/njs/basd/soChange1.6.1/style.css" />
<script src="/portal/njs/basd/soChange1.6.1/jquery.soChange-min.js" type="text/javascript"></script>
</head>

<%
	String iframeresizescript = "http://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/iframeResizeScript.do";
 %>
<body>
<div class="col-2c-1 pdl-10 clearfix">
</div>

<%--<s:iterator value="currentUser.roles" id="role">--%>
	<%--<s:if test ='%{#role.ROLE_ID == "1050"}'>--%>
		<%--<div class="container container-2">--%>
			<%--<!--kefu-right star-->--%>
		    <%--<ul class="kefu-right js_kefu_right">--%>
		        <%--<li class="kefu js_kefu"><a href="#none"><b></b><span>工作区全屏</span></a></li>--%>
		    <%--</ul>--%>
		<%--<div>	--%>
	<%--</s:if>--%>
<%--</s:iterator>--%>
    

<div id="changeDiv">
</div>
</body>
</html>
<script>
$(function(){
	//Drag
	//uedLoader("Drag",function(){
		
	//})
	
	//Tab
	//uedLoader("Tab", function () {	
		$("div.tabspanel").uedTab();
    //});
	//AutoComplete
	//uedLoader("AutoComplete", function () {
		$("#suggest").autocomplete("data.json",{
			formatItem: function(data, i, n, value) {
				return value.split(",")[0];
			},
			formatResult: function(data, value) {
				return value.split(",")[0];
			}
		});
	//});
	
	//关闭首页区块
	$("div.newbox .option>.close").live("click",function(){
		$(this).parents("div.newbox").remove();	
		return false;
	})
	//放大首页区块
	$("div.newbox .option>.max").live("click",function(){
		var _this = $(this);
		var clone = _this.closest("div.newbox").clone(true);
		clone.appendTo("body");
		clone.wrap("<div class='max-panel'></div>");
		clone.find(".option").html("<span class='restore'></span>");
		$(".restore").live("click",function(){$(this).closest(".max-panel").remove();})
		$(".max-panel .newbox .newbox-area").css("height",$(document).height()-$(".text").height()-5);
		var changeDiv = $(".max-panel .newbox .newbox-area").find("div");
		if(changeDiv.attr("id")!=undefined){
			changeDiv.attr("id","change_temp");
			//数字导航切换及自定义当前数字的class
			$('#change_temp .a_bigImg').soChange({
				thumbObj:'#change_temp .ul_change_a2 span',
				thumbNowClass:'on',//自定义导航对象当前class为on
				changeTime:changeDiv.attr("second") * 1000//自定义切换时间ms
		
			});
		}
		return false;
	})
	$("div.newbox .option>.mag").live("click",function(){
		var _this = $(this);
		var url = _this.closest("div.newbox").find("iframe").attr("src");
		var porlet_id = _this.closest("div.newbox").attr("id");
		//window.open(url);
		window.open("fullScreenPanel.do?portalForm.PANEL_ID="+porlet_id, 'big', 'fullscreen=yes')
		return false;
	})
	setInterval(function(){ $(".wordMore ul:eq(0)").animate({"margin-top":"-25px"},1000,function (){
		 $(".wordMore ul:eq(0) li:first").clone().appendTo(".wordMore ul:eq(0)");//把第一个li 赋值到尾部  
		  $(".wordMore ul:eq(0) li:first").remove();//第一个删除
		   $(".wordMore ul:eq(0)").css("margin-top","0")
	  })},2000)
	

	//全屏
    var isFullScreen = window.top.location.href.indexOf("fullWorkArea") > 0;
    $(function () {
        if (isFullScreen) {
            $('.js_kefu_right').find("span").text('退出全屏');
        }
		$(".js_kefu_right").hover(function(){
			$(this).addClass("kefu-index").children(".kefu").show();
		},function(){
			$(this).removeClass("kefu-index").children(".kefu").hide();
		});
		$(".js_kefu").hover(function(){
			$(this).addClass("kefu-index-1");
		},function(){
			$(this).removeClass("kefu-index-1");
		});
	})

	$(".kefu-index-1").live("click",function(){
        if (isFullScreen) {// 退出全屏
            window.parent.close();
        } else {// 进入全屏
            window.open("fullWorkArea.do", 'big', 'fullscreen=1')
        }
		return false;
	})
	  
})

var layout;

$(function(){
	$.ajax({
		url:"getPanelInfo.do",
		type:"post",
		success:function(msg){
			//var userSetting = msg.USER_SETTING;
			//var setElement = "";
			//if(userSetting!=null && userSetting.PORLETS != null){
				//setElement = userSetting.PORLETS;
			//}
			var layoutConfig = msg.LAYOUT_CONFIG;
			var porletConfig = msg.PORLET_CONFIG;
			
			layout = layoutConfig.LAYOUT_ID;
			var $parentDiv = $(".col-2c-1");
			var $col1;
			var $col2;
			if(layout=="1"){
				$col1 = $('<div id="ssss1" name="ssss1" class="col-7">'); 
				$parentDiv.append($col1);
			}else if(layout=="2"){
				$col1 = $('<div id="ssss1" name="ssss1" class="col-1">'); 
				$col2 = $('<div id="ssss2" name="ssss2" class="col-2">');
				$parentDiv.append($col1);
				$parentDiv.append($col2);
			}else if(layout=="3"){
				$col1 = $('<div id="ssss1" name="ssss1" class="col-3">'); 
				$col2 = $('<div id="ssss2" name="ssss2" class="col-4">');
				$parentDiv.append($col1);
				$parentDiv.append($col2);
			}else if(layout=="4"){
				$col1 = $('<div id="ssss1" name="ssss1" class="col-5">'); 
				$col2 = $('<div id="ssss2" name="ssss2" class="col-6">');
				$parentDiv.append($col1);
				$parentDiv.append($col2);
			}else if(layout=="5"){
				$col1 = $('<div id="ssss1" name="ssss1" class="col-8">'); 
				$col2 = $('<div id="ssss2" name="ssss2" class="col-9">');
				$col3 = $('<div id="ssss3" name="ssss3" class="col-10">');
				$parentDiv.append($col1);
				$parentDiv.append($col2);
				$parentDiv.append($col3);
			}else if(layout=="6"){
				$col1 = $('<div id="ssss1" name="ssss1" class="col-11">'); 
				$col2 = $('<div id="ssss2" name="ssss2" class="col-12">');
				$col3 = $('<div id="ssss3" name="ssss3" class="col-13">');
				$parentDiv.append($col1);
				$parentDiv.append($col2);
				$parentDiv.append($col3);
			}else{
				$col1 = $('<div id="ssss1" name="ssss1" class="col-1">'); 
				$col2 = $('<div id="ssss2" name="ssss2" class="col-2">');
				$parentDiv.append($col1);
				$parentDiv.append($col2);
			}
			
			var putIdx = 1 ;
			$.each(porletConfig,function(i,value){
					var $colParent;
					if(value.GROUPNAME != undefined){
						$colParent = $('.'+value.GROUPNAME,$parentDiv);
					}else{
						if(layout=="1"){
							$colParent = $col1;
						}else if(layout=="2"||layout=="3"||layout=="4"){
							if(putIdx%2 != 0){
								$colParent = $col1;
							}else{
								$colParent = $col2;
							}
						}else if(layout=="5"||layout=="6"){
							if(putIdx%3 == 1){
								$colParent = $col1;
							}else if(putIdx%3 == 2){
								$colParent = $col2;
							}else if(putIdx%3 == 0){
								$colParent = $col3;
							}
						}
					}
					
					var areaHeight = value.HEIGHT - 26 ;//26是span class="ttcorner"的高度
					
					try{
						var urlArray = eval("("+value.CONTENT_URL+")");
						var $newbox = $('<div class="newbox" id="'+value.PORLET_ID+'" style="height:'+value.HEIGHT+'px"></div>');
						var $newbox_tt = $('<div class="newbox-tt"><span class="ttcorner"></span><h3><span class="text"></span><div class="option"><span class="max"></span><span class="mag"></span></div></h3></div>');
						$newbox_tt.find(".text").text(value.TITLE);
							
						if(urlArray.length>1){
							var $eachBox = $('<div class="newbox-area" style="height:'+areaHeight+'px"></div>'); 
	    					var $change = $('<div id="change'+putIdx+'" class="changeBox_a1" second="'+value.SECOND+'"></div>');
	    						
							for (var one in urlArray)
	    					{
	    						var $newbox_iframe = $('<iframe name="bd" src="" class="a_bigImg" width="100%" height="100%" frameborder="0" >');
	    						$newbox_iframe.attr("src",urlArray[one].url);
	    						$change.append($newbox_iframe);
	    					}
	    					
	    					var $newbox_ul = $('<ul class="ul_change_a2"></ul>');
	    					
	    					var i=0;
	    					for (var one in urlArray)
	    					{
	    						i++;
	    						var $eachBox_li = $('<li><span>'+i+'</span></li>');
	    						$newbox_ul.append($eachBox_li);
	    					}
	    					
	    					$change.append($newbox_ul);
	    					$eachBox.append($change);
	    					$newbox.append($newbox_tt).append($eachBox);
	    					$colParent.append($newbox);
	    					
	    					//数字导航切换及自定义当前数字的class
							$('#change'+putIdx+' .a_bigImg').soChange({
								thumbObj:'#change'+putIdx+' .ul_change_a2 span',
								thumbNowClass:'on',//自定义导航对象当前class为on
								changeTime:value.SECOND*1000//自定义切换时间ms
						
							});
	    				}else{
	    					var url = urlArray[0].url;
	    					
	    					if(url.indexOf("?")>0){
	    						url = url + "&";
	    					}else{
	    						url = url + "?";
	    					}
	    					url = url + 'iframeresizescript=' + '<%=iframeresizescript%>' + '?panelId=' + value.PORLET_ID;
	    					
	    					var $newbox_area = $('<div class="newbox-area" style="height:'+areaHeight+'px"><iframe src="" width="100%" height="100%" frameborder="0" ></div>');
							$newbox_area.find("iframe").attr("src",url);
							$newbox.append($newbox_tt).append($newbox_area);
							$colParent.append($newbox);
							
	    				}
	    				
    					putIdx++;
					}catch(e){
						var $newbox = $('<div class="newbox" id="'+value.PORLET_ID+'" style="height:'+value.HEIGHT+'px"></div>');
						var $newbox_tt = $('<div class="newbox-tt"><span class="ttcorner"></span><h3><span class="text"></span><div class="option"><span class="max"></span><span class="mag"></span></div></h3></div>');
						$newbox_tt.find(".text").text(value.TITLE);
						var $newbox_area = $('<div class="newbox-area" style="height:'+areaHeight+'px"><iframe src="" width="100%" height="100%" frameborder="0" ></div>');
						$newbox_area.find("iframe").attr("src",value.CONTENT_URL);
						$newbox.append($newbox_tt).append($newbox_area);
						$colParent.append($newbox);
						putIdx++;
					}
					
					
				//}
			});
			$col1.append('<div class="clear"></div>');
            if($col2){
                $col2.append('<div class="clear"></div>');
            }
			initDrag();
		}
	});
	var initDrag = function(){
			$('.newbox').each(function(i,n){
				var _this = $(n);
				var _parent = _this.parent();
				var dragfn = _this.uedDrag({handler:_this.find('.newbox-tt>h3').children(":not('.option')")});
				document.onselectstart = function(){
					return false;
				}
				dragfn.bind("StartDrag",function(current){
					changeZIndex(current.target[0]);
					_this.css({"-moz-user-select":"none","-khtml-user-select":"none"});
				})
				dragfn.bind("StopDrag",function(current){
					clearTimeout(timeout);
					var timeout = setTimeout(function(){
						var reg = /\d+/;
						//var left = reg.exec(_this.css("left"));
						//var top = reg.exec(_this.css("top"));
						var width = reg.exec(_this.width());
						var height = reg.exec(_this.height());
						var _parent = _this.parent();
						var diffX = current.diffX;
						var diffY = current.diffY;
						var index = Math.round((diffY+current.top)/height);
						if(_parent.hasClass("col-1")){
							if(diffX>width/2 && diffX<width*2){
								var col2 = _parent.next(".col-2");
								if(col2.children().length>index){
									_this.css({left:"",top:""}).insertBefore(col2.children().eq(index));
								}else{
									_this.css({left:"",top:""}).appendTo(col2);	
								}
							}else if(Math.abs(diffY)>height/2 && _this.index()!=index){
								_this.css({left:"",top:""}).insertBefore(_parent.children().eq(index));
							}
						}else if(_parent.hasClass("col-2")){
							if(-diffX>=width/2 && -diffX<width*2){
								var col1 = _parent.prev(".col-1");
								if(col1.children().length>index){
									_this.css({left:"",top:""}).insertBefore(col1.children().eq(index));
								}else{
									_this.css({left:"",top:""}).appendTo(col1);	
								}
							}else if(Math.abs(diffY)>height/2 && _this.index()!=index){
								_this.css({left:"",top:""}).insertBefore(_parent.children().eq(index));
							}
						}else if(_parent.hasClass("col-3")){
							if(diffX>width/2 && diffX<width*2){
								var col2 = _parent.next(".col-4");
								if(col2.children().length>index){
									_this.css({left:"",top:""}).insertBefore(col2.children().eq(index));
								}else{
									_this.css({left:"",top:""}).appendTo(col2);	
								}
							}else if(Math.abs(diffY)>height/2 && _this.index()!=index){
								_this.css({left:"",top:""}).insertBefore(_parent.children().eq(index));
							}
						}else if(_parent.hasClass("col-4")){
							if(-diffX>=width/2 && -diffX<width*2){
								var col1 = _parent.prev(".col-3");
								if(col1.children().length>index){
									_this.css({left:"",top:""}).insertBefore(col1.children().eq(index));
								}else{
									_this.css({left:"",top:""}).appendTo(col1);	
								}
							}else if(Math.abs(diffY)>height/2 && _this.index()!=index){
								_this.css({left:"",top:""}).insertBefore(_parent.children().eq(index));
							}
						}else if(_parent.hasClass("col-5")){
							if(diffX>width/2 && diffX<width*2){
								var col2 = _parent.next(".col-6");
								if(col2.children().length>index){
									_this.css({left:"",top:""}).insertBefore(col2.children().eq(index));
								}else{
									_this.css({left:"",top:""}).appendTo(col2);	
								}
							}else if(Math.abs(diffY)>height/2 && _this.index()!=index){
								_this.css({left:"",top:""}).insertBefore(_parent.children().eq(index));
							}
						}else if(_parent.hasClass("col-6")){
							if(-diffX>=width/2 && -diffX<width*2){
								var col1 = _parent.prev(".col-5");
								if(col1.children().length>index){
									_this.css({left:"",top:""}).insertBefore(col1.children().eq(index));
								}else{
									_this.css({left:"",top:""}).appendTo(col1);	
								}
							}else if(Math.abs(diffY)>height/2 && _this.index()!=index){
								_this.css({left:"",top:""}).insertBefore(_parent.children().eq(index));
							}
						}else if(_parent.hasClass("col-8")){
							if(diffX>width/2 && diffX<width*2){
								var col2 = _parent.next(".col-9");
								if(col2.children().length>index){
									_this.css({left:"",top:""}).insertBefore(col2.children().eq(index));
								}else{
									_this.css({left:"",top:""}).appendTo(col2);	
								}
							}if(diffX>(width/2+parseInt(width)) && diffX<width*3){
								var col3 = _parent.next(".col-9").next(".col-10");
								if(col3.children().length>index){
									_this.css({left:"",top:""}).insertBefore(col3.children().eq(index));
								}else{
									_this.css({left:"",top:""}).appendTo(col3);	
								}
							}else if(Math.abs(diffY)>height/2 && _this.index()!=index){
								_this.css({left:"",top:""}).insertBefore(_parent.children().eq(index));
							}
						}else if(_parent.hasClass("col-9")){
							if(-diffX>width/2 && -diffX<width*2){
								var col1 = _parent.prev(".col-8");
								if(col1.children().length>index){
									_this.css({left:"",top:""}).insertBefore(col1.children().eq(index));
								}else{
									_this.css({left:"",top:""}).appendTo(col1);	
								}
							}if(diffX>width/2 && diffX<width*2){
								var col3 = _parent.next(".col-10");
								if(col3.children().length>index){
									_this.css({left:"",top:""}).insertBefore(col3.children().eq(index));
								}else{
									_this.css({left:"",top:""}).appendTo(col3);	
								}
							}else if(Math.abs(diffY)>height/2 && _this.index()!=index){
								_this.css({left:"",top:""}).insertBefore(_parent.children().eq(index));
							}
						}else if(_parent.hasClass("col-10")){
							if(-diffX>(width/2+parseInt(width)) && -diffX<width*2){
								var col2 = _parent.prev(".col-9");
								if(col2.children().length>index){
									_this.css({left:"",top:""}).insertBefore(col2.children().eq(index));
								}else{
									_this.css({left:"",top:""}).appendTo(col2);	
								}
							}else if(-diffX>(width/2+parseInt(width)) && -diffX<width*3){
								var col1 = _parent.prev(".col-9").prev(".col-8");
								if(col1.children().length>index){
									_this.css({left:"",top:""}).insertBefore(col1.children().eq(index));
								}else{
									_this.css({left:"",top:""}).appendTo(col1);	
								}
							}else if(Math.abs(diffY)>height/2 && _this.index()!=index){
								_this.css({left:"",top:""}).insertBefore(_parent.children().eq(index));
							}
						}else if(_parent.hasClass("col-11")){
							if(diffX>width/2 && diffX<width*2){
								var col2 = _parent.next(".col-12");
								if(col2.children().length>index){
									_this.css({left:"",top:""}).insertBefore(col2.children().eq(index));
								}else{
									_this.css({left:"",top:""}).appendTo(col2);	
								}
							}if(diffX>(width/2+parseInt(width)) && diffX<width*3){
								var col3 = _parent.next(".col-12").next(".col-13");
								if(col3.children().length>index){
									_this.css({left:"",top:""}).insertBefore(col3.children().eq(index));
								}else{
									_this.css({left:"",top:""}).appendTo(col3);	
								}
							}else if(Math.abs(diffY)>height/2 && _this.index()!=index){
								_this.css({left:"",top:""}).insertBefore(_parent.children().eq(index));
							}
						}else if(_parent.hasClass("col-12")){
							if(-diffX>width/2 && -diffX<width*2){
								var col1 = _parent.prev(".col-11");
								if(col1.children().length>index){
									_this.css({left:"",top:""}).insertBefore(col1.children().eq(index));
								}else{
									_this.css({left:"",top:""}).appendTo(col1);	
								}
							}if(diffX>width/2 && diffX<width*2){
								var col3 = _parent.next(".col-13");
								if(col3.children().length>index){
									_this.css({left:"",top:""}).insertBefore(col3.children().eq(index));
								}else{
									_this.css({left:"",top:""}).appendTo(col3);	
								}
							}else if(Math.abs(diffY)>height/2 && _this.index()!=index){
								_this.css({left:"",top:""}).insertBefore(_parent.children().eq(index));
							}
						}else if(_parent.hasClass("col-13")){
							if(-diffX>(width/2+parseInt(width)) && -diffX<width*2){
								var col2 = _parent.prev(".col-12");
								if(col2.children().length>index){
									_this.css({left:"",top:""}).insertBefore(col2.children().eq(index));
								}else{
									_this.css({left:"",top:""}).appendTo(col2);	
								}
							}else if(-diffX>(width/2+parseInt(width)) && -diffX<width*3){
								var col1 = _parent.prev(".col-12").prev(".col-11");
								if(col1.children().length>index){
									_this.css({left:"",top:""}).insertBefore(col1.children().eq(index));
								}else{
									_this.css({left:"",top:""}).appendTo(col1);	
								}
							}else if(Math.abs(diffY)>height/2 && _this.index()!=index){
								_this.css({left:"",top:""}).insertBefore(_parent.children().eq(index));
							}
						}
						savePozition();
	    				
						return false;
					},500)
				})
			})
		}
		function changeZIndex(obj){
			$(obj).css("z-index", 2).siblings("div").css("z-index", 1);
		}
		
		function savePozition(){
			var panels = $('.newbox');
			//var panels = $('.col-13 .newbox');
			for (var i=1;i<panels.length;i++)
			{
				var panel = panels[i];
				//if($(panel).parent(".col-12").hasClass("col-12"))
					
				var top = $(panels[i]).offset().top;
				if($(panels[i]).offset().top<$(panels[i-1]).offset().top)
				{
					for (var j=0;j<panels.length;j++)
					{
						if(top<$(panels[j]).offset().top)
						{
							for(k=i;k>j;k--)
							{
								panels[k] = panels[k-1];
							}
							panels[j] = panel;
							break;
						}
					}
				}
			}
			
			var panelIds = "";
			var v = "";
			for (var i=0;i<panels.length;i++)
			{
				panelIds = panelIds + panels[i].id + ",";
				v = v + panels[i].id + "," + $(panels[i]).parent().attr('class') + ";";
			}

			$.ajax({
				url:"savePanelOrder.do?panelIds="+v,
				type:"post",
				success:function(msg){
				}
			});
		}
		
		
});
</script>